package com.ssx.cloud.controller;


import com.ssx.cloud.entity.Admin;
import com.ssx.cloud.entity.CommonResult;
import com.ssx.cloud.service.IAdminService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ssx
 * @since 2020-11-19
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private IAdminService adminService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/add")
    public CommonResult<Admin> add(@RequestBody Admin admin){
        boolean save = adminService.save(admin);
        if (save){
            return new CommonResult(200,"插入成功lol,serverPort="+serverPort,admin);
        }else {
            return new CommonResult<>(444,"插入失败TAT");
        }
    }

    @GetMapping("/get/{id}")
    public CommonResult<Admin> getById(@PathVariable("id") Integer id){
        Admin admin = adminService.getById(id);
        if (admin!=null){
            return new CommonResult<>(200,"获取成功lol",admin);
        }else {
            return new CommonResult<>(444,"获取失败TAT");
        }
    }

    @RequestMapping("/lb")
    public String lb(){
        return serverPort;
    }
}
